package com.java.demo;

import java.util.Random;

public class VerifyCodeGenerator {
    public static void main(String[] args) {
        String code = getCode(6);
        System.out.println(code);
    }
    public  static String getCode(int length) {
        String code = "";
        for(int i = 0; i < length; i++) {
            // 随机生成大写小写和数字
            int type = (int) (Math.random() * 3); // [0, 3)
            switch (type) {
                case 0:
                    code += (int)(Math.random() * 10);
                    break;
                case 1:
                    int num1 = (int)(Math.random() * 26);
                    char c1 = (char) ('A' + num1);
                    code += c1;
                    break;
                case 2:
                    int num2 = (int)(Math.random() * 26);
                    char c2 = (char) ('a' + num2);
                    code += c2;
                    break;
            }
        }
        return code;
    }
}
